package com.xc.ezplan.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xc.ezplan.admin.entity.AdminDept;
import com.xc.ezplan.admin.entity.AdminEmailConfig;
import com.xc.ezplan.admin.entity.AdminEmailTemplate;
import com.xc.ezplan.admin.entity.AdminQiniuConfig;
import com.xc.ezplan.admin.service.AdminEmailTemplateService;
import com.xc.ezplan.admin.mapper.AdminEmailTemplateMapper;
import com.xc.ezplan.admin.vo.AdminEmailTemplateVo;
import com.xc.ezplan.cache.constants.RedisKey;
import com.xc.ezplan.cache.utils.CacheUtil;
import com.xc.ezplan.core.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lixingchen
 * @date 2022/12/10
 * @description 邮件模板实现类
 */
@Service
@Primary
@RequiredArgsConstructor
public class AdminEmailTemplateServiceImpl extends ServiceImpl<AdminEmailTemplateMapper, AdminEmailTemplate>
		implements AdminEmailTemplateService {
	private final AdminEmailTemplateMapper adminEmailTemplateMapper;

	@Override
	public void createEmailTemplate(AdminEmailTemplateVo adminEmailTemplateVo) {
		AdminEmailTemplate adminEmailTemplate = new AdminEmailTemplate();
		BeanUtils.copyProperties(adminEmailTemplateVo,adminEmailTemplate);
		adminEmailTemplateMapper.insert(adminEmailTemplate);
	}

	@Override
	public void updateEmailTemplate(AdminEmailTemplateVo adminEmailTemplateVo) {

	}

	@Override
	public void deleteEmailTemplate(List<Long> ids) {
		adminEmailTemplateMapper.deleteBatchIds(ids);
	}

	@Override
	public Object queryEmailTemplate(Long id) {
		return adminEmailTemplateMapper.selectById(id);
	}

	@Override
	public Object queryAllEmailTemplate(String keyWord) {
		LambdaQueryWrapper<AdminEmailTemplate> queryWrapper = new QueryWrapper<AdminEmailTemplate>().lambda().like(
				StringUtils.isNotBlank(keyWord), AdminEmailTemplate::getName,
				keyWord);
		return adminEmailTemplateMapper.selectList(queryWrapper);
	}
}
